package com.doit.day03

object _07_算子 {
  def main(args: Array[String]): Unit = {
    /*    val list: List[Int] = List(1, 2, 3, 4, 5)
        val max: Int = list.max
        val min: Int = list.min*/

/*    val list: List[Order] = List(Order("u001", "o001", "g001", "c001", 19.9, 20),
      Order("u003", "o003", "g003", "c001", 29.9, 10),
      Order("u002", "o002", "g002", "c002", 49.9, 11),
      Order("u006", "o006", "g006", "c003", 39.9, 14),
      Order("u005", "o005", "g005", "c003", 79.9, 17),
      Order("u008", "o008", "g008", "c005", 59.9, 14),
      Order("u009", "o009", "g009", "c005", 89.9, 12),
      Order("u007", "o007", "g007", "c005", 99.9, 15),
      Order("u004", "o004", "g004", "c003", 49.9, 12),
      Order("u010", "o010", "g010", "c003", 29.9, 17))*/

    /*    list.min(new Ordering[Order] {
          override def compare(x: Order, y: Order) = ???
        })*/
//    val order: Order = list.minBy(_.goods_num)
//    println(order)

/*    val ints: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8)

    val iterator: Iterator[List[Int]] = ints.grouped(3)
    while (iterator.hasNext){
      println(iterator.next())
    }*/

    val list: List[Int] = List(1, 2, 3, 4, 5)
    //聚合算子
//    val res: Int = list.reduce((a:Int,b:Int)=>{a-b})

    val res: Int = list.reduceRight((a: Int, b: Int) => {
      a - b
    }) //3

    //fold  折叠
    val res1: Int = list.fold(10)(_ + _)


    val ints: List[Int] = List(3, 4, 5, 6, 7, 8)

    val res2: List[Int] = list.intersect(ints)//3 4 5
    val res3: List[Int] = list.diff(ints) // 1 2
    val res4: List[Int] = list.union(ints).distinct // 1 2 3 4 5 6 7 8  List(1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8)

    println(res2)
    println(res3)
    println(res4)

    //zip   拉链的意思   机器学习算法的时候会用得到
    val res5: List[(Int, Int)] = list.zip(ints)
    println(res5)

    val index: List[(Int, Int)] = list.zipWithIndex
    println(index)


    //List
    val list1: List[Any] = List(1,2, "hello", true, (1, "zss"), 'a')
    //我想将这个集合中的整数全部取出来并且* 10  ==》 List(10,20)

/*    //遍历判断取出来放在新的list里面
    val list2: List[Any] = list1.filter(word => word.isInstanceOf[Int])

    list2.map(word=>{
      word.asInstanceOf[Int] * 10
    }).foreach(println)*/

    //偏函数
    val value: PartialFunction[Any, Int] = new PartialFunction[Any, Int] {
      //这个方法就类似于filter
      override def isDefinedAt(x: Any) = x.isInstanceOf[Int]

      //类似于map
      override def apply(v1: Any) = v1.asInstanceOf[Int] * 10
    }

    val ints1: List[Int] = list1.collect(value)
    println(ints1)




  }

}
